package com.xhwl.logistics.converter.mapstruct;

import com.xhwl.logistics.bo.input.QueryVehicleOvernightConditionBO;
import com.xhwl.logistics.component.VehicleConfigProperty;
import com.xhwl.logistics.enums.VehicleCardTypeEnum;
import com.xhwl.logistics.enums.VehiclePassTypeEnum;
import com.xhwl.logistics.enums.VehicleRechargeTypeEnum;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Named;
import org.mapstruct.NullValueMappingStrategy;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Objects;

@Mapper(componentModel = "spring", nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public abstract class VehicleCommonConverter {

    @Autowired
    private VehicleConfigProperty vehicleConfigProperty;

    public QueryVehicleOvernightConditionBO toQueryVehicleOvernightConditionBO(Boolean overnight) {
        if (Objects.nonNull(overnight)) {
            QueryVehicleOvernightConditionBO queryVehicleOvernightConditionBO = new QueryVehicleOvernightConditionBO();
            queryVehicleOvernightConditionBO.setOvernight(overnight);
            queryVehicleOvernightConditionBO.setMysqlTemporalIntervalExpression(vehicleConfigProperty.getDay() + " " + vehicleConfigProperty.getHour() + ":" + vehicleConfigProperty.getMinute());
            return queryVehicleOvernightConditionBO;
        }
        return null;
    }

    public Integer toVehiclePassType(String vehiclePassTypeDescription) {
        if (StringUtils.isNotEmpty(vehiclePassTypeDescription)) {
            return VehiclePassTypeEnum.toVehiclePassTypeEnum(vehiclePassTypeDescription).getId();
        }
        return null;
    }

    //*********cent*********
    @Named("vehicleCardTypeDescription2VehicleCardTypeId")
    public Integer toVehicleCardType(String vehicleCardTypeDescription) {
        if (StringUtils.isNotEmpty(vehicleCardTypeDescription)) {
            return VehicleCardTypeEnum.toVehicleCardTypeEnum(vehicleCardTypeDescription).getId();
        }
        return null;
    }

    @Named("vehicleCardTypeId2VehicleCardTypeDescription")
    public String toVehicleCardType(Integer vehicleCardTypeId) {
        return VehicleCardTypeEnum.toVehicleCardTypeEnum(vehicleCardTypeId).getDescription();
    }
    //*********cent*********

    //*********Ke Top*********
    @Named("keTopCardTypeId2VehicleCardTypeId")
    public Integer toVehicleCardTypeByKeTop(Integer keTopCardType) {
        return VehicleCardTypeEnum.toVehicleCardTypeEnumByKeTop(keTopCardType).getId();
    }
    @Named("keTopRechargeTypeId2VehicleRechargeTypeId")
    public Integer toVehicleRechargeTypeByKeTop(Integer keTopRechargeType) {
        return VehicleRechargeTypeEnum.toVehicleRechargeTypeEnumByKeTop(keTopRechargeType).getId();
    }
    //*********Ke Top*********

}
